package com.cangchu.ui.fragment;

import android.support.v4.app.Fragment;
import com.cangchu.MyApplication;
import com.cangchu.ui.activity.BaseActivity;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 * 基础Fragment 类，逐渐扩充
 * Created by 张博文 on 2016/11/2.
 */
public class BaseFragment<T> extends Fragment {

    private Class<T> cls;

    //通过配置泛型，实现自动获取日志Tag
    public BaseFragment() {
        Type genType = getClass().getGenericSuperclass();
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
        cls = (Class) params[0];
    }

    public BaseActivity getBaseActivity() {
        return (BaseActivity) getActivity();
    }

    public MyApplication getMyApplication() {
        return (MyApplication) getActivity().getApplication();
    }


    /**
     * 返回日志Tag，方便配置，减少代码
     *
     * @return
     */
    protected String getLogTag() {
        return cls.getSimpleName();
    }


}
